package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.InvStrategyRecord;
import com.ruoyi.system.service.IInvStrategyRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投资策略历史Controller
 * 
 * @author ruoyi
 * @date 2022-01-12
 */
@Controller
@RequestMapping("/book/record")
public class InvStrategyRecordController extends BaseController
{
    private String prefix = "book/record";

    @Autowired
    private IInvStrategyRecordService invStrategyRecordService;

    @RequiresPermissions("book:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询投资策略历史列表
     */
    @RequiresPermissions("book:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(InvStrategyRecord invStrategyRecord)
    {
        startPage();
        List<InvStrategyRecord> list = invStrategyRecordService.selectInvStrategyRecordList(invStrategyRecord);
        return getDataTable(list);
    }

    /**
     * 导出投资策略历史列表
     */
    @RequiresPermissions("book:record:export")
    @Log(title = "投资策略历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(InvStrategyRecord invStrategyRecord)
    {
        List<InvStrategyRecord> list = invStrategyRecordService.selectInvStrategyRecordList(invStrategyRecord);
        ExcelUtil<InvStrategyRecord> util = new ExcelUtil<InvStrategyRecord>(InvStrategyRecord.class);
        return util.exportExcel(list, "投资策略历史数据");
    }

    /**
     * 新增投资策略历史
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存投资策略历史
     */
    @RequiresPermissions("book:record:add")
    @Log(title = "投资策略历史", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(InvStrategyRecord invStrategyRecord)
    {
        return toAjax(invStrategyRecordService.insertInvStrategyRecord(invStrategyRecord));
    }

    /**
     * 修改投资策略历史
     */
    @RequiresPermissions("book:record:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        InvStrategyRecord invStrategyRecord = invStrategyRecordService.selectInvStrategyRecordById(id);
        mmap.put("invStrategyRecord", invStrategyRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存投资策略历史
     */
    @RequiresPermissions("book:record:edit")
    @Log(title = "投资策略历史", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(InvStrategyRecord invStrategyRecord)
    {
        return toAjax(invStrategyRecordService.updateInvStrategyRecord(invStrategyRecord));
    }

    /**
     * 删除投资策略历史
     */
    @RequiresPermissions("book:record:remove")
    @Log(title = "投资策略历史", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(invStrategyRecordService.deleteInvStrategyRecordByIds(ids));
    }
}
